package com.catmiao.spark.stream

import org.apache.spark.SparkConf
import org.apache.spark.streaming.dstream.{DStream, ReceiverInputDStream}
import org.apache.spark.streaming.{Seconds, StreamingContext, StreamingContextState}

import java.lang.Thread

/**
 * @title: SparkStreaming01_WordCount
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/3/25 00:31
 */
object SparkStreaming11_Resume {

  def main(args: Array[String]): Unit = {

    /**
     * 从检查点恢复数据
     */

    val ssc  = StreamingContext.getActiveOrCreate("cp",()=>{
      val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("SparkStreaming")
      val ssc = new StreamingContext(sparkConf, Seconds(3))

      val line: ReceiverInputDStream[String] = ssc.socketTextStream("localhost", 9999)

      val wordToOne: DStream[(String, Int)] = line.map((_, 1))

      ssc

    })

    ssc.checkpoint("cp")

    ssc.start()
    ssc.awaitTermination()



  }


}
